import numpy as np


def main():
    data = np.loadtxt('./dataset/preprocessed/wine.data', delimiter=',', skiprows=1)
    print(data)
    data = data[:, 1:]

    mean = np.mean(data, axis=0)
    centered_data = data - mean
    cov_matrix = np.cov(centered_data.T)
    eigen_values, eigen_vectors = np.linalg.eig(cov_matrix)

    sorted_indices = np.argsort(eigen_values)[::-1]
    eigen_vectors = eigen_vectors[:, sorted_indices]
    
    # 选择前两个特征向量
    top_two_eigen_vectors = eigen_vectors[:, :2]
    result_data = centered_data.dot(top_two_eigen_vectors)

    print(result_data)
    

if __name__ == '__main__':
    main()
    